package com.example.myweb.Repository.JpaRepository;

import com.example.myweb.Domain.Entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {
    // Spring Data JPA 会根据方法名自动生成实现
    Optional<User> findByEmail(String email);
    Optional<User> findByPhoneNumber(String phoneNumber);
    Optional<User> findByResetToken(String resetToken); // 新增方法

    Optional<User> findByUserId(Long userId); // 明确通过userId查找
    boolean existsByEmail(String email);
    boolean existsByPhoneNumber(String phoneNumber);

    @Query("SELECT count(f) FROM Follow f WHERE f.follower.userId = :userId")
    Long countFollowingByUserId(@Param("userId") Long userId);

    @Query("SELECT count(f) FROM Follow f WHERE f.followed.userId = :userId")
    Long countFollowersByUserId(@Param("userId") Long userId);
}